package com.sbs.admin.web;

import com.sbs.admin.vo.Result;
import com.sbs.admin.vo.UserVo;
import com.sbs.base.util.SpringContextHolder;
import com.sbs.admin.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@RestController()
@RequestMapping("/test")
@Validated
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);
    @GetMapping("validreq")
    public Result<String> validReq(@Valid @RequestBody UserVo userVO){
        return Result.success(userVO.toString());
    }
    @GetMapping("validreq/{num}")
    public Result<String> validReq(@PathVariable("num")@Min(1)@Max(20) String num){
        return Result.success(num);
    }

    @GetMapping("/exception")
    public String exception() throws Exception {
        throw new Exception("test exception");
    }
    @GetMapping("/springholder")
    public String springHolder() {
        UserDTO userDTO = SpringContextHolder.getBean(UserDTO.class);
        return userDTO.toString();
    }
    @GetMapping("/hello")
    public String test() {
        String result = "hello world";
        return result;
    }

    @GetMapping("log")
    public String log() {
        logger.trace("trace-msg");
        logger.debug("debug-msg");
        logger.warn("warn-msg");
        logger.info("info-msg");
        logger.error("error-msg");
        return "log";
    }

}
